<template>
    <!-- 收藏 item -->
    <div>
        <el-skeleton :loading="loading" animated>
            <template slot="template">
                <div style="padding: 5px;">
                    <el-skeleton-item variant="h3" style="width: 80%;" />
                    <div style="display: flex; align-items: center; justify-items: space-between; margin-top: 16px; height: 16px;">
                        <el-skeleton-item variant="text" style="margin-right: 20px;" />
                        <el-skeleton-item variant="text" style="margin-right: 100px; width: 30%" />
                        <el-skeleton-item variant="text" style="width: 30%;" />
                    </div>
                </div>
            </template>
        </el-skeleton>

        <div class="search-item" v-show="!loading">
            <div class="top">
                <div :class="[ isContentTime ? 'title-top': 'title' , isTagLong ? 'title-right':'' ]" @click="handleClick">
                    {{title}}
                    <slot name="tag"></slot>
                </div>
                <div v-if="isBouTime" class="time-and-icon">
                    <slot name="time">{{time2}}</slot>
                    <!-- <slot name="icon">
                        <i class="iconfont primary">&#xe62b;</i>
                    </slot> -->
                </div>
            </div>

            <slot name="content">
                <div style="margin-top:12px">
                    <my-tag v-show="!!data.area">{{dataArea}}</my-tag>
                    <my-tag v-show="!isTagLong && !!data.noticetype">{{data.noticetype}}</my-tag>
                    <my-tag v-show="!!data.industry && data.industry !='未知'">{{data.industry}}</my-tag>
                    <my-tag v-show="!!data.price && data.noticetype == '中标公告'" :is-default="false">
                        {{ (Math.floor(data.price)/10000).toFixed(4) + '万元' }}
                    </my-tag>

                    <slot name="time" v-if="isContentTime">
                        <span style="color:#909399;">&nbsp;{{time2}}</span>
                    </slot>
                    <span v-show="!data.area">&nbsp;</span>
                </div>
            </slot>

            <slot name="footer">
                <div class="myfooter" v-if="!isBouTime">
                    <span slot="time">{{time2}}</span>
                    <div></div>
                </div>
            </slot>

        </div>
    </div>
</template>

<script>
import TOOLBAR_MIXIN from '@components/sys/item-tool-bar/mixins/index';

export default {
    mixins: [TOOLBAR_MIXIN],
    props: {
        data: {
            type: Object,
            default: () => {},
        },
        //
        title: {
            type: String,
            default: '',
        },
        time: {
            type: String,
            // type: Number,
            default: '',
        },
        //标签长度过长，需要处理
        isTagLong: {
            type: Boolean,
            default: false,
        },
        //在内容区域显示时间
        isContentTime: {
            type: Boolean,
            default: false,
        },
        //在标题后 显示时间
        isBouTime: {
            type: Boolean,
            default: false,
        },

        //
        tagList: {
            type: [Array, String, Boolean],
            default: false,
        },
        tagName: {
            type: String,
            default: '',
        },
        type: {
            type: String,
            default: '',
        },
        tagType: {
            type: String,
            default: '',
        },
        icon: {
            type: String,
            default: '&#xe62b;',
        },
    },
    data() {
        return {
            loading: true,
            time2: '',
            dataArea: '',
            // .replace('河北省-','')
        };
    },
    watch: {
        time(val) {
            this.doMounted();
        },
    },
    methods: {
        handleClick() {
            this.$emit('titleClick', this.data);
        },

        // 处理时间
        dateFormat2(time) {
            if (!time) return;
            //判断日期是不是 yyyy-MM-DD
            if (time.indexOf('-') != '-1') {
                return time;
            } else {
                // 时间戳
                time -= 0;
                let times = this.formDate(new Date(time), 'yyyy-MM-DD'); //"yyyy-MM-DD HH:mm:ss"
                if (this.isContentTime) {
                    times = this.formDate(new Date(time), 'yyyy-MM-DD HH:mm:ss');
                }
                return times;
            }
        },

        formDate(data, format) {
            let time = {
                'M+': data.getMonth() + 1,
                'D+': data.getDate(),
                'H+': data.getHours(),
                'm+': data.getMinutes(),
                's+': data.getSeconds(),
            };
            if (/(y+)/i.test(format)) {
                format = format.replace(RegExp.$1, (data.getFullYear() + '').substr(4 - RegExp.$1.length));
            }
            for (let k in time) {
                if (new RegExp('(' + k + ')').test(format)) {
                    format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? time[k] : ('00' + time[k]).substr(('' + time[k]).length));
                }
            }
            return format;
        },
        doMounted() {
            this.loading = false;
            this.time2 = this.time;
            this.time2 = this.dateFormat2(this.time2);

            this.dataArea = this.data.area;
            // ****************************
            if (this.isTagLong) {
                if (this.data.area) {
                    this.dataArea = this.data.area.replace('河北省-', '');
                }
            }

            // if (this.isTagLong) {
            // delete this.data.industry;
            // .replace('河北省-','')
            // }
        },
    },
    mounted() {
        this.doMounted();
    },
};
</script>

<style lang="scss" scoped>
@import '@css/var.scss';

// .el-card .el-card__body{
//     padding: 15px !important;
// }

.search-item {
    position: relative;
    color: #333;

    .items {
        margin-top: 15px;
    }

    .top {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: baseline;

        .title {
            font-weight: 600;
            font-size: 16px;
            width: 100%;
            // 标题超出一行隐藏显示...
            // white-space: nowrap;
            // overflow: hidden;
            // text-overflow: ellipsis;
            cursor: pointer;

            &:hover {
                color: $primaryColor;
            }
        }

        .title-top {
            font-weight: 600;
            font-size: 16px;
            width: 100%;
            margin-bottom: 8px;
            cursor: pointer;

            &:hover {
                color: $primaryColor;
            }
        }
        .title-right {
            font-size: 14px;
            font-weight: normal;
            overflow: hidden !important;
            text-overflow: ellipsis;

            display: -webkit-box;
            -webkit-line-clamp: 2; // 控制多行的行数
            -webkit-box-orient: vertical;
        }

        .time-and-icon {
            width: 104px;
            display: flex;
            color: $infoColor;

            .iconfont {
                cursor: pointer;
            }
        }
    }
    .el-tag.el-tag--info {
        margin: 0 0px 0 0;
        padding: 0 4px;
    }

    .myfooter {
        position: absolute;
        bottom: 0px;
        right: 0px;
        margin-right: -8px;
        // background-color: pink;
        display: flex;
        justify-content: flex-end;
        color: $infoColor;

        div {
            margin-left: 14px;
            align-items: baseline;
            color: $infoColor;
        }
    }
}
</style>